Skip to content

fix(web): preserve scroll when collapsing large changed-files trees#1113

Open
CodeZeno wants to merge 1 commit intopingdotgg:mainfrom
CodeZeno:wip/changed-files-scroll-fix-v2
Open

fix(web): preserve scroll when collapsing large changed-files trees#1113
CodeZeno wants to merge 1 commit intopingdotgg:mainfrom
CodeZeno:wip/changed-files-scroll-fix-v2

Conversation

@CodeZeno
Copy link

@CodeZeno CodeZeno commented Mar 15, 2026

Summary

Fix chat scroll jumps when collapsing very large changed-files trees.

Problem

When a changed-files section contains hundreds of entries, collapsing the tree can shrink the rendered message enough that the timeline repositions the viewport unexpectedly. In practice this makes the collapse controls feel broken because the user gets pulled away from the message they were interacting with.

What changed

  • stop virtualizer scroll compensation when the resized row is currently visible
  • mark changed-files collapse and directory toggle controls with data-scroll-anchor-ignore so click-anchor restoration does not interfere with those interactions

Why

The bug happens during an intentional height change inside the message the user is actively viewing. In that case, preserving the current viewport is more stable than trying to compensate for the size change. The virtualizer can still adjust scroll for off-screen rows, but visible changed-files interactions now keep the user anchored in place.

UI Changes

Before:
https://github.com/user-attachments/assets/60f06a27-9776-4c6d-b553-611fbbf5b2a0

  • Notice tree collapses correctly but the user is then immediately taken to the top of thread
  • 'Collapse all' button immediately takes the user to the top of thread

After:
https://github.com/user-attachments/assets/eacd53a5-66f9-41e7-b70c-7b4de1b0292d

  • Tree collapses work fine, keeping position
  • 'Collapse all' button also keeps position

Good to have

Might also be nice to have the default as collapsed if the number of changed files is greater then a certain number?

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Note

Preserve scroll position when collapsing changed-files trees in the chat timeline

  • Adds data-scroll-anchor-ignore to directory toggle buttons in ChangedFilesTree.tsx and the collapse/expand button in MessagesTimeline.tsx so clicks on these buttons don't trigger scroll anchor adjustments.
  • Updates shouldAdjustScrollPositionOnItemSizeChange in MessagesTimeline to skip scroll adjustments when the resized item is within the viewport, preventing jarring scroll jumps when collapsing large file trees.
  • Behavioral Change: scroll position adjustments now only fire when the resized item is outside the viewport and the remaining distance to the bottom exceeds AUTO_SCROLL_BOTTOM_THRESHOLD_PX.

Macroscope summarized 7b0d5e8.

@coderabbitai
Copy link

coderabbitai bot commented Mar 15, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: eff497c1-37b9-490d-bb56-890b5ce25eb4

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can get early access to new features in CodeRabbit.

Enable the early_access setting to enable early access features such as new models, tools, and more.

@github-actions github-actions bot added size:XS 0-9 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Mar 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant